{template 'web/hairsalon/base_menu'}
<div class="top_tab">
    <a href="{php echo $this->createWebUrl('staff')}" class="layui-btn {if $operation != 'display'}layui-btn-primary{/if}">管理员工</a>
    <a href="{php echo $this->createWebUrl('staff',array('op'=>'post'))}" class="layui-btn {if $operation != 'post'}layui-btn-primary{/if}">添加员工</a>
    <a href="{php echo $this->createWebUrl('staff',array('op'=>'staffcate'))}" class="layui-btn {if $operation != 'staffcate'}layui-btn-primary{/if}">管理工种</a>
    {if $operation == 'display'}
    <div class="secrchinput">
        <button><i class="fa fa-search"></i></button>
        <input type="text" id="txtTopupSeachStr" placeholder="输入">
    </div>
    {/if}
</div>
{if $operation == 'post'}
<div class="panelbox">
    <form action="" method="post" class="layui-form" enctype="multipart/form-data">
        <input type="hidden" name="id" value="{php echo $id}" />
        <div class="panelbox-head">{if !$id}添加新员工{else}编辑【{$item['realname']}】{/if}</div>
        <div class="panelbox-body">
            <div class="layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block">
                    <input type="radio" name="status" value="1" title="开启"  {if $item['status']}checked{/if} />
                    <input type="radio" name="status" value="0" title="禁用" {if !$item['status']}checked{/if} />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">工号</label>
                <div class="layui-input-block">
                    <input type="text" name="useracount" maxlength="10" class="layui-input" value="{$item['useracount']}" {if $id}disabled{/if}/>
                    <div class="help-block">用于登录使用，不能以0开头。如“A01”。注意：提交不可更改</div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">所属店铺</label>
                <div class="layui-input-block form-inline">
                    <input name="pcate" type="hidden" value="{php echo $item['pcate'] ? $item['pcate'] : $shopid}" />
                    <input readonly class="layui-input" value="{php echo $item['pcate'] ? $groupary[$item['pcate']] : $groupary[$shopid]}" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">角色权限</label>
                <div class="layui-input-block">
                    <input type="radio" name="permission" value="1" title="员工" {if $item['permission'] == 1 || empty($item['permission'])}checked{/if} />
                    <input type="radio" name="permission" value="3" title="店长" {if $item['permission'] == 3}checked{/if} />
                    <div class="help-block">仅【店长】可登陆后台</div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">所属工种</label>
                <div class="layui-input-block">
                    <Select name="staffcate">
                        <option value="">请选择</option>
                        {loop $list $row}
                        <option value="{$row['id']}" {if $item['staffcate']==$row['id']}selected{/if}>{$row['title']}</option>
                        {/loop}
                    </Select>
                    <div class="help-block"></div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">工作状态</label>
                <div class="layui-input-block">
                    <Select name="workstatus">
                        <option value="">请选择</option>
                        <option value="0" {if $item['workstatus']==0}selected{/if}>试用</option>
                        <option value="1" {if $item['workstatus']==1}selected{/if}>正式</option>
                        <option value="2" {if $item['workstatus']==2}selected{/if}>学徒</option>
                        <option value="3" {if $item['workstatus']==3}selected{/if}>实习</option>
                        <option value="4" {if $item['workstatus']==4}selected{/if}>休假</option>
                        <option value="5" {if $item['workstatus']==5}selected{/if}>离职</option>
                    </Select>
                    <div class="help-block"></div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">openid</label>
                <div class="layui-input-block">
                    <input type="text" name="openid" class="layui-input" value="{$item['openid']}" />
                    <div class="help-block">请在粉丝列表中查找-<a href="./index.php?c=mc&a=fans" target="_blank">粉丝列表</a></div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">头像</label>
                <div class="layui-input-block">
                    {php echo tpl_form_field_image('headimg', $item['headimg']);}
                    <div class="help-block">100*100px</div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">姓名</label>
                <div class="layui-input-block">
                    <input type="text" name="realname" class="layui-input" value="{$item['realname']}" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">电话</label>
                <div class="layui-input-block">
                    <input type="text" name="mobile" class="layui-input" value="{$item['mobile']}" />
                    <div class="help-block">仅为记录</div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">身份证</label>
                <div class="layui-input-block">
                    <input type="text" name="idcard" class="layui-input" value="{$item['idcard']}" />
                    <div class="help-block">仅为记录</div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">生日</label>
                <div class="layui-input-block">
                    <input type="text" name="birday" class="layui-input" value="{$item['birday']}" />
                    <div class="help-block">仅为记录</div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">入职时间</label>
                <div class="layui-input-block">
                    {php echo tpl_form_field_date('entrytime', $item['entrytime'] ? $item['entrytime'] : date('Y-m-d'), false)}
                    <div class="help-block"></div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">合同时间</label>
                <div class="layui-input-block">
                    {php echo tpl_form_field_date('contracttime', $item['contracttime'] ? $item['contracttime'] : date('Y-m-d'), false)}
                    <div class="help-block"></div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">底薪</label>
                <div class="layui-input-block">
                    <input type="text" name="basesalary" class="layui-input" value="{php echo $item['basesalary'] ? $this->_2money($item['basesalary']): '0'}" />
                    <div class="help-block"></div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">银行卡</label>
                <div class="layui-input-block form-inline">
                    <input type="text" name="bankname" placeholder="开户银行" class="layui-input" value="{$item['bankname']}" />
                    <input type="text" name="bankcard" placeholder="卡号" class="layui-input" value="{$item['bankcard']}" />
                    <div class="help-block"></div>
                </div>
            </div>

            {if empty($id)}
            <div class="layui-form-item">
                <label class="layui-form-label">输入密码</label>
                <div class="layui-input-block">
                    <input type="password" name="password" class="layui-input"/>
                    <div class="help-block">不少于6位英文、数字、符号</div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">确认密码</label>
                <div class="layui-input-block">
                    <input type="password" name="password2" class="layui-input"/>
                    <div class="help-block"></div>
                </div>
            </div>
            {else}
            <div class="layui-form-item">
                <label class="layui-form-label">修改密码</label>
                <div class="layui-input-block">
                    <button type="button" class="layui-btn layui-btn-primary" onclick="changepassword()">修改密码</button>
                    <div class="help-block"></div>
                </div>
            </div>
            {/if}
        </div>
        <div class="panelbox-foot">
            <input type="hidden" name="token" value="{$_W['token']}" />
            <input class="layui-btn" type="submit" lay-submit="" name="submit" lay-filter="submitbtn" value="提交">
        </div>
    </form>
</div>
{elseif $operation == 'display'}
<div class="panelbox">
    <form action="" method="post" class="layui-form" enctype="multipart/form-data">
        <div class="panelbox-head">
            <A href="{php echo $this->createWebUrl('staff',array('op'=>'post'))}"><i class="fa fa-plus"></i>新增员工</A>
        </div>
        <div class="panelbox-body">
            <div class="layui-form">
                <table class="layui-table">
                    <thead>
                    <tr>
                        <th style="width:60px"></th>
                        <th>工号</th>
                        <th>姓名</th>
                        <th>电话</th>
                        <th>工种</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {loop $list $row}
                    <tr>
                        <td></td>
                        <td>{$row['useracount']}</td>
                        <td>{$row['realname']}</td>
                        <td>{$row['mobile']}</td>
                        <td>{php echo $staffary[$row['staffcate']]}</td>
                        <td>{if $row['status']}<span class="label label-info">正常</span>{else}<span class="label label-default">未开通</span>{/if} {php echo $workstatus[$row['workstatus']]}</td>
                        <td class="text-right"><a href="{php echo $this->createWebUrl('staff',array('op'=>'post','id'=>$row['id']))}" class="layui-btn layui-btn-normal layui-btn-small"><i class="layui-icon">&#xe642;</i></a> <a href="javascript:deleteContent('{php echo $this->createWebUrl('staff',array('op'=>'delete','id'=>$row['id']))}')" class="layui-btn layui-btn-danger layui-btn-small"><i class="layui-icon">&#xe640;</i></a></td>
                    </tr>
                    {/loop}
                    </tbody>
                </table>
            </div>
        </div>
        <div class="panelbox-foot">  </div>
    </form>
</div>
<script language="javascript">
    layui.use(['layer', 'laypage', 'element','form'], function(){
        var layer = layui.layer
                ,laypage = layui.laypage
                ,element = layui.element
                ,form = layui.form;
        form.render();
        form.on('submit(submitbtn)', function(data){

            return true;
        });
        form.on('checkbox(allChoose)', function(data){
            var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
            child.each(function(index, item){
                item.checked = data.elem.checked;
            });
            form.render('checkbox');
        });
    });
    function changepassword(){
        layer.prompt({title: '修改密码', formType: 1}, function(pass, index){
            if(pass.length<6){
                layer.msg('密码不能少于6位');
                return;
            }
            layer.close(index);
            layer.prompt({title:'确认刚才输入的密码',formType:1}, function(text, index){
                layer.close(index);
                if(pass!=text){
                    layer.msg('两次输入的密码不一样，请重新输入',{time:2000}, function(){
                        changepassword();
                    });
                    return;
                }
                var index2=layer.load(1, {shade: [0.5,'#fff']});
                $.post("{php echo $this->createWebUrl('staff',array('op'=>'changepass'))}",{"id":"{$id}","pass":pass},function(data){
                    layer.close(index2);
                    if(!data.success){
                        layer.msg(data.msg,{icon:1,time:2000});
                        return;
                    }
                    layer.msg('密码修改成功',{icon:1,time:2000});
                },'json');
            });
        });
    }
</script>
{elseif $operation == 'staffcate'}
<div class="panelbox">
    <form action="" method="post" class="layui-form" enctype="multipart/form-data">
        <div class="panelbox-head">
            <A href="#" onclick="editBox(0)"><i class="fa fa-plus"></i>新增工种</A>
        </div>
        <div class="panelbox-body">
            <div class="layui-form">
                <table class="layui-table">
                    <colgroup>
                        <col width="50">
                        <col width="150">
                        <col>
                        <col>
                    </colgroup>
                    <thead>
                    <tr>
                        <th style="width:60px"></th>
                        <th>名称</th>
                        <th style="text-align: right">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {loop $list $row}
                    <tr>
                        <td></td>
                        <td>{$row['title']}</td>
                        <td class="text-right"><a href="JavaScript:editBox({$row['id']})" class="layui-btn layui-btn-normal layui-btn-small"><i class="layui-icon">&#xe642;</i></a> <a href="javascript:deleteContent('{php echo $this->createWebUrl('staff',array('op'=>'deletecate','id'=>$row['id']))}')" class="layui-btn layui-btn-danger layui-btn-small"><i class="layui-icon">&#xe640;</i></a></td>
                    </tr>
                    {/loop}
                    </tbody>
                </table>
            </div>
        </div>
        <div class="panelbox-foot">  </div>
    </form>
</div>
<div id="editcatebox" style="display:none">
    <form id="editcateform" class="layui-form" action="" style="padding:15px">
        <input type="hidden" name="id" />
        <div class="layui-form-item">
            <input type="text" name="title" lay-verify="required" placeholder="请输入名称" class="layui-input">
        </div>
    </form>
</div>
<script language="JavaScript">
    function editBox(id){
        var index2=layer.load(1, {shade: [0.5,'#fff']});
        console.log(1);
        var til= id==0 ? "添加":"修改";
        $("#editcateform")[0].reset();
        console.log(2)
        $.post("{php echo $this->createWebUrl('staff',array('op'=>'getstaffcate'))}",{"id":id},function(data){
            console.log(3)
            console.dir(data);
            layer.close(index2);
            if(!data.success){
                layer.msg(data.msg,{icon:1,time:2000});
                return;
            }
            $("#editcateform").find("input[name='id']").val(id);
            if(id==0){
                $("#editcateform").find("input[name='title']").val("");
            }else{
                var items=data.item;
                $("#editcateform").find("input[name='title']").val(items.title);
            }
            layer.open({
                type: 1,
                title:til,
                btn: ['确认', '关闭'],
                btn1:function(index,layero){
                    index2=layer.load(1, {shade: [0.5,'#fff']});
                    var param={"title":$("#editcateform").find("input[name='title']").val(),"id":id}
                    $.post("{php echo $this->createWebUrl('staff',array('op'=>'staffcatepost'))}",param,function(data2){
                        layer.close(index2);
                        if(!data2.success){
                            layer.msg(data2.msg,{icon:1,time:2000});
                            return;
                        }
                        location.reload();
                    },'json');
                },
                content: $("#editcatebox").show(),
                end:function(){
                    $("#editcatebox").hide();
                }
            });
        },'json');

    }
</script>
{/if}

<script language="javascript">
    layui.use(['layer', 'laypage', 'element','form'], function(){
        var layer = layui.layer
                ,laypage = layui.laypage
                ,element = layui.element
                ,form = layui.form;
        form.render();

    });
    function deleteContent(url){
        layer.confirm('确认删除此内容？删除后将不可恢复', {}, function(){
            location.href=url;
        });
    }
</script>